package com.htthorizon.system.controller;

import com.htthorizon.common.core.domain.R;
import com.htthorizon.common.redis.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;

/**
 * @author Brilliant
 */
@RestController
@RequestMapping("/redis")
public class RedisController {

    @Autowired
    private RedisService redisService;

    @GetMapping("/get/{key}")
    public Object get(@PathVariable String key){
        Collection<String> keys = redisService.keys("*");
        for (String k:keys){
            if (k.contains(key)){
                Object cacheObject = redisService.getExpire(k);
                return cacheObject;
            }
        }
        return null;

    }

    public R test(){
        try{
            Collection<String> keys = redisService.keys("*");
            for (String k:keys){
                redisService.deleteObject(k);
            }
            System.out.println("删除redis成功");
        }catch (Exception e){
            System.out.println("删除redis失败");
        }
        return R.ok();
    }


}
